<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 引入easyui的样式 -->
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/default/easyui.css">
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/themes/icon.css">
<!-- js文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
/**
$(function(){
	$('#StuList').datagrid({
		url:"findAllCourse", 
		queryParams: {			
			sid:"${currentUser.sid}",
		}
	});
});
*/
$(function(){
	//更改底部工具栏
	var pager = $('#StuList').datagrid('getPager');	
	  pager.pagination({
		pageList: [10,20,30],
	});
})	

/**
//选择课程
function addcourse(){
  //获取课程ID
    var cid = $('#StuList').datagrid('getSelected').cid;
  	var sid =${sessionScope.currentUser.sid}
   //发送请求
  		window.location.href="addRecord?cid="+cid+"&sid="+sid;
  	 }
	}	
	*/



//增加课程
function addcourse(){
	//1.获取被选中需要增加的课程
	var data = $('#StuList').datagrid('getSelections')	
	var sid =${sessionScope.currentUser.sid}
	 if(data.length==0){
			$.messager.show({
				title:'警告',
				msg:'请选中需要选择的课程',
				timeout:1500,
				showType:'slide',
					style:{
						left:100,
						right:'',
						top:100
					}
		  		});
	 }else{
		//2.声明一个空的数组	装选中的ID
		var cids=[];
		for (var  i= 0;  i< data.length; i++) {
			cids.push(data[i].cid)	
			}		
			$.messager.confirm('确认选择', '您确定要选择这'+data.length+'门课程吗？', function(r){				
					
					if (r){					
				   $.ajax({
				  	type:"post",
				  	url:"addRecord",
				  	data:{"cids":cids,"sid":sid},
					dataType:"text",
				 	success:function(data){
				 		if(data==1){
			    			//提示选课成功
			    			$.messager.alert('提示','选课成功','info',function(){
			    				$("#StuList").datagrid('reload');
			    			});   
			    			
			    		}else{
			    			//提示选课失败
			    			$.messager.alert('提示','选课失败！');
			    			$("#StuList").datagrid('reload');
			    		}
			    	}
			    })
			}else{
				$("#StuList").datagrid('uncheckAll')
			}
		});
}
}


//课程查找
$(function(){
	//点击搜索的时候只能功能
	$('#search').searchbox({
	    searcher:function(value){
	   		//如果搜索内容为空刷新当前页面
	    	if(value==""){
				    window.location.reload();
	   		}else{	   			
	    	$.ajax({
	   		type:"post",
	    	url:'selectCourse',

	    	data:{"name":value},
	    	dataType:"json",
	    	success:function(data){
	    		//加载搜索结果
	    		$("#StuList").datagrid('loadData',data); 
	    			}
	   			})	   		 
	   		}	    	
	    }	   
	})
})
</script>
<body>
	 <table id="StuList" title="课程信息查询" class="easyui-datagrid"
            toolbar="#toolbar" pagination="true" fit="true" pageSize="20"
           	url="findAllCourse"
            rownumbers="true" fitColumns="true" border="false">         
        <thead>
            <tr>
            	<th field="ck" checkbox="true"></th>
                <th field="cid"  hidden="true">课程ID</th>
                <th field="cname" width="50" resizable="false">课程名字</th>
                <th field="cbtime" width="50" resizable="false">开始时间</th>
                <th field="cetime" width="50" resizable="false">结束时间</th>
                <th field="ccount" width="50" resizable="false">最多选课人数</th>
                <th field="tname" width="50" resizable="false">授课老师</th>
            </tr>
        </thead>
    </table>  
        <div id="toolbar">
         <input id="search" class="easyui-searchbox"  style="width:250px">
         <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addcourse()">选课</a>                       
  		</div> 
</body>
</html>